<template>
  <!-- vue3组件中的模板结构可以没有根标签div -->
  <h2>{{ sum }}</h2>
  <button @click="sum++">sum++</button>

  <hr />
  <h1>一个人的信息</h1>
  <h2>姓名：{{ name }}</h2>
  <h2>年龄：{{ age }}</h2>
  <h2>薪资：{{ job.j1.title }}K</h2>
  <button @click="name += '~'">修改i姓名</button>
  <button @click="age++">点我加1</button>
  <button @click="job.j1.title++">涨薪</button>
</template>

<script>
import { ref, reactive, toRefs, readonly, shallowReadonly } from "vue";

export default {
  name: "App",
  setup() {
    // Data
    // let person = shallowReactive({ //只考虑第一层数据的响应
    let person = reactive({
      age: 18,
      name: "管",
      job: {
        j1: {
          title: 20,
        },
      },
    });
    // let x = ref({
    let sum = ref(0);
    person = shallowReadonly(person);
    return {
      sum,
      // person,
      ...toRefs(person),
    };
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
